import math


class Vector3:
    def __init__(self, x=0, y=0, z=0):
        self.x = x
        self.y = y
        self.z = z

    def clone(self):
        return Vector3(self.x, self.y, self.z)

    def length(self) -> float:
        return math.sqrt(self.x * self.x + self.y * self.y + self.z * self.z)

    def cross(self, v):
        ox = self.y * v.z - self.z * v.y
        oy = self.z * v.x - self.x * v.z
        oz = self.x * v.y - self.y * v.x
        return Vector3(ox, oy, oz)

    def divide(self, v):
        self.x /= v.x
        self.y /= v.y
        self.z /= v.z
        return self

    def multiply_scalar(self, scalar):
        self.x *= scalar
        self.y *= scalar
        self.z *= scalar
        return self

    def divide_scalar(self, scalar):
        return self.multiply_scalar(1 / scalar)

    def normalize(self):
        return self.divide_scalar(self.length() or 1)

    def distance_to_squared(self, v):
        dx = self.x - v.x
        dy = self.y - v.y
        dz = self.z - v.z
        return dx * dx + dy * dy + dz * dz

    def distance_to(self, v):
        return math.sqrt(self.distance_to_squared(v))


_vector = Vector3()
